#!/bin/bash
#GITURL="https://github.com/robbyrussell/oh-my-zsh"
#FILENAME=".oh-my-zsh"
GITURL=$1
FILENAME=$2
FILODER=(`echo $GITURL | awk -F "[/]" '{print $(NF-1),$NF}' | awk -F "." '{print $1}'`)
if [[ -z $FILENAME ]]
then
  FILENAME=${FILODER[${#FILODER[@]}-1]}
fi
if [[ ! -z $3 ]] && [[ -d $3 ]] && [[ -z ${unline_path} ]]
then
PREHOME=$3
elif [[ ! -z ${unline_path} ]]
then
PREHOME=${unline_path}
else
PREHOME=${HOME}"/unline"
fi
echo "gitclone shell script get parent path="${PREHOME}
echo "anayse git url="${FILODER[0]}" and "${FILODER[1]}
rm -rf ${FILENAME}
if [[ -d ${PREHOME}/${FILODER[0]}/${FILODER[1]} ]]
then
  #mkdir -p ${FILENAME}/
  PARENTPATH=$(dirname ${FILENAME})
  if [[ ! -d ${PARENTPATH} ]]
  then
    mkdir -p ${PARENTPATH}
  fi
  echo "${PREHOME}/${FILODER[0]}/${FILODER[1]} ${FILENAME}"
  cp -R ${PREHOME}/${FILODER[0]}/${FILODER[1]}/ ${FILENAME}/
  # mv ${PARENTPATH}/${FILODER[1]} ${FILENAME}
fi
if [[ ! -d $FILENAME ]]
then
GS=`git clone $GITURL $FILENAME`
fi
#FILODER=(a oh-my-zsh)
# 检测clone文件夹是否存在
if [[ -d $FILENAME ]]
then
  echo "exit"
else
  echo "我觉得网络不同......"
  #mkdir -p ${FILENAME}/
  #cp -R ${PREHOME}/${FILODER[0]}/${FILODER[1]} ${FILENAME}
fi
